package com.readaloud.wicket;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.PropertyModel;


@SuppressWarnings("unused")
public class RegistrationPanel extends Panel {

	private static final long serialVersionUID = -4193482962608288298L;

	public RegistrationPanel(String id) {
		super(id);
		add(new RegistrationForm("RegistrationForm"));
	}

	private class RegistrationForm extends Form<Component> {

		private static final long serialVersionUID = 9142506655979020833L;
		private String userId;
		private String pwd;
		private String username;
		private String selected;
		
		public RegistrationForm(String id) {
			super(id);
			add(new TextField<String>("userId", new PropertyModel<String>(this, "userId")));
			add(new PasswordTextField("pwd", new PropertyModel<String>(this, "pwd")));
			add(new TextField<String>("username", new PropertyModel<String>(this, "username")));
			
			List<String> list = new ArrayList<String>();
             list.add("Reader");
             list.add("Author");
             
			DropDownChoice<String> userTypeList = new DropDownChoice<String>("userType", new PropertyModel<String>(this, "selected"), list);
            add(userTypeList);
			setMarkupId("registration-form");
		}
		
		@Override
		protected void onSubmit() {
			ArrayList<String> paramList = new ArrayList<String>();
			paramList.add(getUserId());
			paramList.add(getPwd());
			paramList.add(getUsername());
			paramList.add(getSelected());
            WicketApplication.get().getInvertedIndexDao().saveUser(paramList);
            setResponsePage(IndexPage.class);
		}

		public String getUserId() {
			return userId;
		}

		public void setUserId(String userId) {
			this.userId = userId;
		}

		public String getPwd() {
			return pwd;
		}

		public void setPwd(String pwd) {
			this.pwd = pwd;
		}

		public String getUsername() {
			return username;
		}

		public void setUsername(String username) {
			this.username = username;
		}

		public String getSelected() {
			return selected;
		}

		public void setSelected(String selected) {
			this.selected = selected;
		}

		
	}
}
